﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebStudio.Business.Entity;
using WebStudio.Business.Rule;

public partial class Admin_MessageDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Admin_User"] == null || Session["Admin_User"].ToString() == "")
        {
            Response.Redirect("~/Admin/Login.aspx");
        }
        if (messageEntity == null)
        {
            ApplicationHelper.AddStartupScript(this, "alert('该留言不存在');location.href='MessageMge.aspx';");
        }
        else
        {
            if (messageEntity.ReplyContent != null && messageEntity.ReplyContent != "")
            {
                txtReply.Text = messageEntity.ReplyContent.Trim();
            }
        }
    }

    public MessageEntity messageEntity
    {
        get
        {
            if (string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                return null;
            }
            else
            {
                try
                {
                    int mid = Convert.ToInt32(Request.QueryString["id"]);

                    return MessageRule.GetMessageEntity(mid);
                }
                catch
                {
                    return null;
                }
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        MessageEntity info = new MessageEntity();
        info.Status = 1;
        info.ReplyContent = txtReply.Text.Trim();
        info.ReplyDate = DateTime.Now;
        info.ReplyUserName = Session["Admin_User"].ToString();
        info.MessageId = messageEntity.MessageId;
        if (MessageRule.SaveMessageInfor(info))
        {
            ApplicationHelper.AddStartupScript(this, "alert('回复成功');location.href='MessageMge.aspx';");
        }
        else
        {
            ApplicationHelper.ShowClientMessage(this, "回复失败");
            return;
        }
    }
}
